#include<stdio.h>
#include"process.h"
#include<unistd.h>
#include<stdlib.h>
#include<time.h>
double gtotal=1024.0;
double speed=1.0;
//函数类型指针
typedef void(*callback_t)(double,double);

double SpeedFloat(double start, double range)//浮动上下限
{
	int int_range=(int)range;
	return start + rand()%int_range + (range-int_range);

}
void Download(double total ,callback_t  cb)//回调函数:维护性、模块与模块间耦合度好
{
	srand(time(NULL));
	double curr=0.0;
	while(curr<total)
	{
		cb(total,curr);
		curr+=SpeedFloat(speed,4.3);//模拟下载
		if(curr>total)
		{
			curr=total;
			cb(total,curr);//用break无法显示出100%的状态不够完整
		}
		usleep(30000);
	}

}
int main()
{

	Download(20.0,FlushProcess);
	Download(200.0,FlushProcess);
	Download(2000.0,FlushProcess);
	//printf("Begin compelling...\n");
	//Process();
	//printf("Done!\n");
	
	return 0;

}
